/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package MongoDAL;

import DALFactory.IRouteMapper;
import com.mongodb.BasicDBObject;
import com.mongodb.DBCollection;
import com.mongodb.DBObject;
import com.mongodb.util.JSON;
import net.sf.json.JSONObject;

/**
 *
 * @author Administrator
 */
public class MongoRouteMapper implements IRouteMapper {

    public MongoRouteMapper() {
    }

    @Override
    public boolean exiRouteByID(String ID) {
        MongoStatement mstm = new MongoStatement();
        DBCollection coll = mstm.QueryTable("Route");
        DBObject target = new BasicDBObject();
        target.put("_id", ID);
        DBObject myDoc = coll.findOne(target);
        if (myDoc != null) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public JSONObject getRouteByID(String ID) {
        MongoStatement mstm = new MongoStatement();
        DBCollection coll = mstm.QueryTable("Route");
        DBObject target = new BasicDBObject();
        target.put("_id", ID);
        DBObject myDoc = coll.findOne(target);
        return JSONObject.fromObject(myDoc);
    }

    @Override
    public void savaeRoute(JSONObject route) {
        MongoStatement mstm = new MongoStatement();
        DBCollection coll = mstm.QueryTable("Route");
        DBObject dbObject = (DBObject) JSON.parse(route.toString());
        coll.insert(dbObject);
    }
}
